package edu.hawaii.ics414;

import java.util.HashMap;
import java.util.Map;
import android.os.AsyncTask;
import android.util.Log;

/**
 * Adds a game to the user's favorites.
 * 
 * @author Matthew Mizumoto
 * 
 */
public class AddToFavorites extends AsyncTask<String, Void, Boolean> {

  @Override
  /*
   * Required by the AsyncTask class. Sends data to the appropriate php page for updates/queries
   * (non-Javadoc)
   * 
   * @param params A variable amount of Strings to send as form data.
   * 
   * @see android.os.AsyncTask#doInBackground(Params[])
   */
  protected Boolean doInBackground(String... params) {
    String username = (params.length > 0) ? params[0] : "";
    String gameName = (params.length > 1) ? params[1] : "";

    Map<String, String> requestParams = new HashMap<String, String>();
    requestParams.put("username", username);
    requestParams.put("gameName", gameName);

    String response =
        Ajax.send("http://ratethatgame.web44.net/ics414/add_favorite.php", requestParams);
    if (response != null) {
      Log.wtf("", response);
      return Boolean.parseBoolean(response.trim());
    }
    return null;
  }
}
